﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Workflow.ComponentModel;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace JHL.SharepointDesignerActions.TextActions
{

    public class StringStartWith : Activity
    {
        public static DependencyProperty StringToCheckProperty =
            DependencyProperty.Register("StringToCheck", typeof(string), typeof(StringStartWith));
        [Category("Text Actions"), Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string StringToCheck
        {
            get
            {
                return Convert.ToString(base.GetValue(StringToCheckProperty));
            }
            set
            {
                base.SetValue(StringToCheckProperty, value);
            }
        }

        public static DependencyProperty InputStringProperty =
            DependencyProperty.Register("InputString", typeof(string), typeof(StringStartWith));
        [Category("Text Actions"), Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string InputString
        {
            get
            {
                return Convert.ToString(base.GetValue(InputStringProperty));
            }
            set
            {
                base.SetValue(InputStringProperty, value);
            }
        }

        public static DependencyProperty ReturnValueProperty =
            DependencyProperty.Register("ReturnValue", typeof(bool), typeof(StringStartWith));
        [Category("Text Actions"), Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public bool ReturnValue
        {
            get
            {
                return Convert.ToBoolean(base.GetValue(ReturnValueProperty));
            }
            set
            {
                base.SetValue(ReturnValueProperty, value);
            }
        }


        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (string.IsNullOrEmpty(this.InputString))
            {
                this.ReturnValue = false;
            }
            else
            {
                if (string.IsNullOrEmpty(this.StringToCheck))
                    this.ReturnValue = false;
                else
                {
                    if (this.InputString.StartsWith(this.StringToCheck))
                        this.ReturnValue = true;
                    else
                        this.ReturnValue = false;
                }
            }

            return ActivityExecutionStatus.Closed;
        }

        private void InitializeComponent()
        {
            // 
            // StringStartWith
            // 
            this.Name = "StringStartWith";

        }
    }
}
